//
//  AppDelegate+Demo.m
//  STBasicsApp
//
//  Created by jerry on 2019/5/3.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "AppDelegate+Demo.h"

@implementation AppDelegate (Demo)

///demo入口01-(Tabbar布局样式)
-(void)initDemo01{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    D1TabBarViewController *vc = [[D1TabBarViewController alloc] init];
    STBaseNavigationViewController *naVC = [[STBaseNavigationViewController alloc] initWithRootViewController:vc];
    self.window.rootViewController = naVC;
    [self.window makeKeyWindow];
}

///demo入口02-(抽屉布局样式)
-(void)initDemo02{
    
    //1、初始化控制器
    UIViewController *centerVC = [[D2DrawerCenterViewController alloc]init];
    UIViewController *leftVC = [[D2DrawerLeftViewController alloc]init];
    //UIViewController *rightVC = [[LitterLRightViewController alloc]init];
    
    //2、初始化导航控制器
    UINavigationController *centerNvaVC = [[UINavigationController alloc]initWithRootViewController:centerVC];
    [centerNvaVC setRestorationIdentifier:@"CenterNavigationControllerRestorationKey"];
    
    UINavigationController *leftNvaVC = [[UINavigationController alloc]initWithRootViewController:leftVC];
    [leftNvaVC setRestorationIdentifier:@"LeftNavigationControllerRestorationKey"];
    
    //UINavigationController *rightNvaVC = [[UINavigationController alloc]initWithRootViewController:rightVC];
    
    //3、使用MMDrawerController
    self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:centerNvaVC leftDrawerViewController:leftNvaVC rightDrawerViewController:nil];
    
    // 不显示阴影
    [self.drawerController setShowsShadow:NO];
    [self.drawerController setRestorationIdentifier:@"MMDrawer"];
    
    //4、设置打开/关闭抽屉的手势
    self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
    self.drawerController.closeDrawerGestureModeMask =MMCloseDrawerGestureModeAll;
    //5、设置左右两边抽屉显示的多少
    self.drawerController.maximumLeftDrawerWidth = 200.0;
    self.drawerController.maximumRightDrawerWidth = 200.0;
    
    //6、初始化窗口、设置根控制器、显示窗口
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.window setRootViewController:self.drawerController];
    [self.window makeKeyAndVisible];
    
}

///demo入口03
-(void)initDemo03{
 
    //1、初始化控制器
    UIViewController *centerVC = [[D2TabBarViewController alloc]init];
    UIViewController *leftVC = [[D2DrawerLeftViewController alloc]init];
    
    //2、初始化导航控制器
    [centerVC setRestorationIdentifier:@"CenterNavigationControllerRestorationKey"];
    
    UINavigationController *leftNvaVC = [[UINavigationController alloc]initWithRootViewController:leftVC];
    [leftNvaVC setRestorationIdentifier:@"LeftNavigationControllerRestorationKey"];
    
    //3、使用MMDrawerController
    self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:centerVC leftDrawerViewController:leftNvaVC rightDrawerViewController:nil];
    
    // 不显示阴影
    [self.drawerController setShowsShadow:NO];
    [self.drawerController setRestorationIdentifier:@"MMDrawer"];
    
    //4、设置打开/关闭抽屉的手势
    self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
    self.drawerController.closeDrawerGestureModeMask =MMCloseDrawerGestureModeAll;
    //5、设置左右两边抽屉显示的多少
    self.drawerController.maximumLeftDrawerWidth = 200.0;
    self.drawerController.maximumRightDrawerWidth = 200.0;
    
    //6、初始化窗口、设置根控制器、显示窗口
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.window setRootViewController:self.drawerController];
    [self.window makeKeyAndVisible];
    
}

///demo入口04
-(void)initDemo04{
    
}

#pragma mark -

- (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
    NSString * key = [identifierComponents lastObject];
    if([key isEqualToString:@"MMDrawer"]){
        return self.window.rootViewController;
    }
    else if ([key isEqualToString:@"CenterNavigationControllerRestorationKey"]) {
        return ((MMDrawerController *)self.window.rootViewController).centerViewController;
    }
    else if ([key isEqualToString:@"LeftNavigationControllerRestorationKey"]) {
        return ((MMDrawerController *)self.window.rootViewController).leftDrawerViewController;
    }
    else if ([key isEqualToString:@"MMLeftSideDrawerController"]){
        UIViewController * leftVC = ((MMDrawerController *)self.window.rootViewController).leftDrawerViewController;
        if([leftVC isKindOfClass:[UINavigationController class]]){
            return [(UINavigationController*)leftVC topViewController];
        }
        else {
            return leftVC;
        }
    }
    return nil;
}

@end
